import { doGet } from '@/services/http';
import { fetchOptionList } from '@/services/marketingMap';
import modelExtend from '@/utils/modelExtend';

let afterSalesAnalysis = { namespace: 'afterSalesAnalysis' };
afterSalesAnalysis = modelExtend(
  {
    state: {
      options: [],
      trr: [],
    },
    effects: {
      *getOptions({ payload, callback }, { call, put }) {
        const response = yield call(fetchOptionList, payload);
        yield put({ type: 'req', payload: { options: response } });
        return response;
      },
      *getTree({ payload, callback }, { call, put }) {
        const response = yield call(doGet, payload);
        if (response.statusCode === '0') {
          yield put({ type: 'req', payload: { trr: response.data } });
          return response;
        }
      },
    },
    reducers: {
      req(state, action) {
        return {
          ...state,
          ...action.payload,
        };
      },
    },
  },
  afterSalesAnalysis,
);
export default afterSalesAnalysis;
